﻿using System;
using System.Collections.Generic;
using System.Text;

using System.ServiceModel;
using System.Runtime.Serialization;

namespace WcfService
{
    [ServiceContract]
    public interface IWCFService
    {
        [OperationContract]
        string SayHello(string name);

        [OperationContract]
        string SayHelloToUser(User user);
    }

    //会话服务(Sessionful Service) 默认会话服务方式
    //为每次客户端代理(客户端的代理可以跟几个应用程序通讯)连接分配一个服务实例,直到调用Close
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
    public class WCFService : IWCFService
    {

        #region IWCFService 成员

        public string SayHello(string name)
        {
            Console.WriteLine("Hello {0}! Using string...", name);
            return "Hello " + name + "!";
        }

        public string SayHelloToUser(User user)
        {
            Console.WriteLine("Hello! {0}-{1},Using DataContract ", user.FirstName, user.LastName);
            return "Hello " + user.FirstName + "." + user.LastName;
        }

        #endregion
    }

    [DataContract]
    public class User
    {
        [DataMember]
        public string FirstName;
        [DataMember]
        public string LastName;
    }
}
